<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .parent {
      /* 伸缩盒 */
      display: flex;
      /* 设置换行 */
      flex-wrap: wrap;
      /* 设置交叉轴对齐方式 */
      justify-content: center;
      /* width: 1200px; */
    }

    .child {
      flex: 0 1 300px;
      height: 100px;
      border: 1px solid blue;
      margin: 10px;
    }
  </style>
</head>

<body>
  <div class="parent">
    <div class="child"></div>
    <div class="child"></div>
    <div class="child"></div>
    <div class="child"></div>
    <div class="child"></div>
    <div class="child"></div>
    <div class="child"></div>
    <div class="child"></div>
  </div>

</body>

</html>